import axios from "axios";
import 'reflect-metadata'

const Base:ClassDecorator = (target)=>{
  console.log(target);
  target.prototype.xm = 'zhangsan'
  target.prototype.fn=()=>{
    console.log("方法");
    
  }
  
}

const Get = (url:string,page=0)=>{
  const fn:MethodDecorator = (target, _:any, descriptor:PropertyDescriptor)=>{
    console.log(target, _, descriptor)
    const key = Reflect.getMetadata('key',target);
    axios.get(url+page).then(res=>{
      descriptor.value( key ? res.data[key] : res.data)
    })
  }
  return fn;
}
const Result = ()=>{
  const fn:ParameterDecorator = (target,key,index)=>{
    console.log(target,key,index)
    const reflect = Reflect.defineMetadata("key",'result',target)
  }
  return fn;
}
const Name:PropertyDecorator = (target,key)=>{
  console.log(target,key)
}
@Base
class Http{

  @Name
  sx:string

  constructor(){
    this.sx = '张三'
  }

  @Get('https://api.apiopen.top/api/getHaoKanVideo?size=10&page=')
  getList(@Result() data:any){
    //console.log(data)
  }
}

const http = new Http()
